package cn.uikit.demo.recyclerview

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import cn.uikit.demo.databinding.FragmentNormalListBinding
import cn.uikit.demo.databinding.ItemRecyclerContentBinding
import sivin.uikit.adapter2.SimpleAdapter
import sivin.uikit.framework.BindingFragment

class NormalListFragment : BindingFragment<FragmentNormalListBinding>(
    FragmentNormalListBinding::inflate
) {
    private val dataList = mutableListOf<String>()

    private val rvAdapter by lazy {
        SimpleAdapter<String, ItemRecyclerContentBinding>(
            ItemRecyclerContentBinding::inflate
        ) { holder, item, _ ->
            holder.binding.run {
                title.text = item
            }
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.recyclerView.apply {
            adapter = rvAdapter
            layoutManager = LinearLayoutManager(context)
            itemAnimator = null
        }

        for (i in 1..100) {
            dataList.add("标题---${i}")
        }
        rvAdapter.setDataList(dataList)
    }

}